package edu.yzu.testspringboot002.convert;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;

import edu.yzu.testspringboot002.po.DailySchedule;
import edu.yzu.testspringboot002.po.dto.daily.DailyScheduleDTO;
import jodd.util.StringPool;
import org.mapstruct.Mapper;
import org.mapstruct.NullValuePropertyMappingStrategy;

import java.util.HashSet;
import java.util.List;

/**
 *
 * @author yulang
 * @date 2023-08-18
 */

@Mapper(
        componentModel = "spring",
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
public abstract class DailyScheduleConvertMapper {

//    public DailyListVO toDailyScheduleVOList(List<DailySchedule> dailyScheduleList) {
//        List<DailyScheduleVO> scheduleVOList = new ArrayList<>();
//        LocalTime localTime = LocalTime.now();
//        int currentIndex = 0;
//        String userIds = "";
//        if (CollUtil.isNotEmpty(dailyScheduleList)) {
//            for (int i = 0; i < dailyScheduleList.size(); i++) {
//                DailySchedule dailySchedule = dailyScheduleList.get(i);
//                DailyScheduleVO scheduleVO = DailyScheduleVO.builder().title(dailySchedule.getMettingName().concat(" ").concat(dailySchedule.getStartRange())
//                                .concat(" - ").concat(dailySchedule.getEndRange()))
//                        .desc(dailySchedule.getDateDaily().concat(" ").concat(dailySchedule.getStartRange())
//                                .concat(" - ").concat(dailySchedule.getEndRange())).build();
//                scheduleVOList.add(scheduleVO);
//
//                LocalTime startTime = LocalTime.parse(dailySchedule.getStartRange());
//                LocalTime endTime = LocalTime.parse(dailySchedule.getEndRange());
//                if (startTime.isBefore(localTime) && endTime.isAfter(localTime)) {
//                    currentIndex = i;
//                    userIds = dailySchedule.getIntroduction();
//                }
//
//            }
//
//            if(StrUtil.isBlank(userIds)){
//                currentIndex = dailyScheduleList.size() - 1;
//                DailySchedule dailySchedule = dailyScheduleList.get(currentIndex);
//                userIds = dailySchedule.getIntroduction();
//            }
//
//        }
//        return DailyListVO.builder().dailyScheduleVOList(scheduleVOList)
//                .currentIndex(currentIndex).userNames(userIds).build();
//
//    }

    /**
     * @param dailyScheduleDTO
     * @return {@link DailySchedule}
     */
    public abstract DailySchedule toDailySchedulePO(DailyScheduleDTO dailyScheduleDTO);


    public List<Integer> toDailyDoctorIdsList(List<String> doctList, Integer id) {
        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.add(id);
        for (String ids : doctList) {

            int[] split = StrUtil.splitToInt(ids, StringPool.COMMA);

            for (Integer doctId : split) {
                hashSet.add(doctId);
            }
        }
       return ListUtil.toList(hashSet);
    }
}